package com.yunda.AJDeviceService.controller;

import com.yunda.AJDeviceService.common.web.domain.ErlangsAjaxResult;
import com.yunda.AJDeviceService.data.dto.LDPMldpsDto;
import com.yunda.AJDeviceService.service.LDPMService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lq
 * @className LDPMController
 * @description TODO
 * @date 2023/2/10 09:28
 */
@Slf4j
@RestController
@RequestMapping
public class ErlangsLDPMController {


    @Autowired
    private LDPMService ldpmService;


    /**
     * LDPS服务地址请求接口（HTTP）
     * 请求方式：GET
     * @return
     */
    @GetMapping("/service/rest/1.0/ldps")
    public ErlangsAjaxResult getLdpsServiceInfo(LDPMldpsDto ldpMldpsDto) {

        ErlangsAjaxResult erlangsAjaxResult = new ErlangsAjaxResult();

        if(ObjectUtils.isEmpty(ldpMldpsDto)||
                ObjectUtils.isEmpty(ldpMldpsDto.getMethod())||
                ObjectUtils.isEmpty(ldpMldpsDto.getId())||
                ObjectUtils.isEmpty(ldpMldpsDto.getType())||
                ObjectUtils.isEmpty(ldpMldpsDto.getName())||
                ObjectUtils.isEmpty(ldpMldpsDto.getHost())){
            log.error("入参不能为空="+ldpMldpsDto);
            return ErlangsAjaxResult.error(500,"入参不能为空");
        }
        String address = "";
        try {
            address = ldpmService.getLdpsServiceInfo(ldpMldpsDto);

            erlangsAjaxResult = ErlangsAjaxResult.success();
            erlangsAjaxResult.put("address",address);
            return erlangsAjaxResult;
        } catch (Exception e) {
            e.printStackTrace();
            return ErlangsAjaxResult.error(500,e.toString());
        }
    }
}
